package com.liuzu.esys.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.liuzu.esys.bo.GoodBo;
import com.liuzu.esys.pojo.Good;
import com.liuzu.esys.service.GoodService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


@Component
@Scope("prototype")
public class WebGoodListener extends AnalysisEventListener<GoodBo> {

    @Autowired
    GoodService goodService;


    @Override
    public void invoke(GoodBo data, AnalysisContext analysisContext) {
        System.out.println(data);
        Good good = new Good();
        //student.setName(data.getName());
        //属性拷贝
        BeanUtils.copyProperties(data,good);
        goodService.addGood(good);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
